package cn.edu.nwsuaf.examcenter.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.nwsuaf.examcenter.pojo.College;
import cn.edu.nwsuaf.examcenter.pojo.Teacher;
import cn.edu.nwsuaf.examcenter.service.CollegeService;
import cn.edu.nwsuaf.examcenter.service.TeacherService;

@Controller
@RequestMapping(value="/teacher")
public class TeacherController {
	@Resource(name="teacherService")
	private TeacherService teacherService;
	
	@Resource(name="collegeService")
	private CollegeService collegeService;
	
	@ResponseBody
	@RequestMapping(value="/json/loadCollege")
	public List<College> jsonLoadCollege(){
		return collegeService.jsonLoadCollege();
	}
	@ResponseBody
	@RequestMapping(value="/addTeacher",method=RequestMethod.POST)
	public String addTeacher(@ModelAttribute Teacher teacher){
		return teacherService.addTeacher(teacher);
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteTeacher/{teacherNo}")
	public String deleteTeacher(@PathVariable(value="teacherNo")String teacherNo){
		return teacherService.deleteTeacher(teacherNo);
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteTeacherList")
	public String deleteTeacherList(@RequestParam(value="array")String array){
		return teacherService.deleteTeacherList(array);
	}
	
	@ResponseBody
	@RequestMapping(value="/json/loadTeacher/{teacherNo}")
	public Teacher jsonLoadTeacher(@PathVariable(value="teacherNo")String teacherNo){
		return teacherService.jsonLoadTeacher(teacherNo);
	}
	
	@RequestMapping(value="/loadTeacher")
	public String loadTeacher(@RequestParam(value="key", required=false)String key, 
			@RequestParam(value="p", required=false)String p, 
			ModelMap modelMap){
		teacherService.loadTeacher(modelMap);
		return "exam/teacher-list";
	}

}
